package woshiheima7;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
//打印字符输出的个数
public class HashMapDemo1 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符：");
        String line = sc.nextLine();
        //创建HashMap集合
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
//想要打印出来的字符按顺序排列的话就用TreeMap
        //遍历字符串
            for (int i=0;i<line.length();i++){
                char key = line.charAt(i);
                Integer vaule = map.get(key);
                if (vaule==null){
                    map.put(key,1);
                }else {
                    vaule++;
                    map.put(key,vaule);
                }
            }
         //遍历map集合
        StringBuilder sb = new StringBuilder();

        Set<Character> keySet = map.keySet();
        for (Character key: keySet){
            Integer vaule = map.get(key);
            sb.append(key).append("(").append(vaule).append(")");

        }
        String s = sb.toString();
        System.out.println(s);

    }
}
